// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode fieldsfirst 

package net.minecraft;


import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MinecraftUtil
{
    private static final class OS
    {

        public static final OS linux;
        public static final OS solaris;
        public static final OS windows;
        public static final OS macos;
        public static final OS unknown;
        public int id;
        //private static final OS $VALUES[];

     

        static 
        {
            linux = new OS("linux", 0);
            solaris = new OS("solaris", 1);
            windows = new OS("windows", 2);
            macos = new OS("macos", 3);
            unknown = new OS("unknown", 4);
            /*$VALUES = (new OS[] {
                linux, solaris, windows, macos, unknown
            });*/
        }

        private OS(String s, int i)
        {
            id = i;
        }
    }


    private static File workDir = null;
    private static File binDir = null;
    private static File resourcesDis = null;
    private static File optionsFile = null;
    private static File lastloginFile = null;
    private static File jarfileFile = null;
    private static File settingsFile = null;
    private static File savesDir = null;
    private static File tempFolder = null;
    private static File nativesFolder = null;
    public static List<Integer> settings = new ArrayList<Integer>();
    public MinecraftUtil()
    {
    }

    public static File getWorkingDirectory()
    {
        if(workDir == null)
        {
            workDir = getWorkingDirectory("minecraft");
        }
        return workDir;
    }

    public static File getBinFolder()
    {
        if(binDir == null)
        {
            binDir = new File(getWorkingDirectory(), "bin");
        }
        return binDir;
    }

    public static File getResourcesFolder()
    {
        if(resourcesDis == null)
        {
            resourcesDis = new File(getWorkingDirectory(), "resources");
        }
        return resourcesDis;
    }

    public static File getOptionsFile()
    {
        if(optionsFile == null)
        {
            optionsFile = new File(getWorkingDirectory(), "options.txt");
        }
        return optionsFile;
    }

    public static File getLoginFile()
    {
        if(lastloginFile == null)
        {
            lastloginFile = new File(getWorkingDirectory(), "lastlogin");
        }
        return lastloginFile;
    }
    
    public static File getjarfileFile()
    {
        if(jarfileFile == null)
        {
            jarfileFile = new File(getWorkingDirectory(), "jarfile");
        }
        return jarfileFile;
    }

    
    public static File getSettingsFile()
    {
        if(settingsFile == null)
        {
            settingsFile = new File(getWorkingDirectory(), "lsettings");
        }
        return settingsFile;
    }
    public static File getSavesFolder()
    {
        if(savesDir == null)
        {
            savesDir = new File(getWorkingDirectory(), "saves");
        }
        return savesDir;
    }

    public static File getNativesFolder()
    {
        if(nativesFolder == null)
        {
            nativesFolder = new File(getBinFolder(), "natives");
        }
        return nativesFolder;
    }

    public static File getTempFolder()
    {
        if(tempFolder == null)
        {
            tempFolder = new File(System.getProperties().getProperty("java.io.tmpdir"), "MCBKPMNGR");
        }
        if(!tempFolder.exists())
        {
            tempFolder.mkdirs();
        }
        return tempFolder;
    }

    public static File getWorkingDirectory(String s)
    {
        String s1 = System.getProperty("user.home", ".");
        File file;
        switch(getPlatform().id)
        {
        case 0: // '\0'
        case 1: // '\001'
            file = new File(s1, (new StringBuilder()).append('.').append(s).append('/').toString());
            break;

        case 2: // '\002'
            String s2 = System.getenv("APPDATA");
            if(s2 != null)
            {
                file = new File(s2, (new StringBuilder()).append(".").append(s).append('/').toString());
            } else
            {
                file = new File(s1, (new StringBuilder()).append('.').append(s).append('/').toString());
            }
            break;

        case 3: // '\003'
            file = new File(s1, (new StringBuilder()).append("Library/Application Support/").append(s).toString());
            break;

        default:
            file = new File(s1, (new StringBuilder()).append(s).append('/').toString());
            break;
        }
        if(!file.exists() && !file.mkdirs())
        {
            throw new RuntimeException((new StringBuilder()).append("The working directory could not be created: ").append(file).toString());
        } else
        {
            return file;
        }
    }

    private static OS getPlatform()
    {
        String s = System.getProperty("os.name").toLowerCase();
        if(s.contains("win"))
        {
            return OS.windows;
        }
        if(s.contains("mac"))
        {
            return OS.macos;
        }
        if(s.contains("solaris"))
        {
            return OS.solaris;
        }
        if(s.contains("sunos"))
        {
            return OS.solaris;
        }
        if(s.contains("linux"))
        {
            return OS.linux;
        }
        if(s.contains("unix"))
        {
            return OS.linux;
        } else
        {
            return OS.unknown;
        }
    }

    public static String excutePost(String s, String s1)
    {
        HttpURLConnection httpurlconnection = null;
        try
        {
            try
            {
                URL url = new URL(s);
                httpurlconnection = (HttpURLConnection)url.openConnection();
                httpurlconnection.setRequestMethod("POST");
                httpurlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                httpurlconnection.setRequestProperty("Content-Length", Integer.toString(s1.getBytes().length));
                httpurlconnection.setRequestProperty("Content-Language", "en-US");
                httpurlconnection.setUseCaches(false);
                httpurlconnection.setDoInput(true);
                httpurlconnection.setDoOutput(true);
                DataOutputStream dataoutputstream = new DataOutputStream(httpurlconnection.getOutputStream());
                dataoutputstream.writeBytes(s1);
                dataoutputstream.flush();
                dataoutputstream.close();
                java.io.InputStream inputstream = httpurlconnection.getInputStream();
                BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream));
                StringBuffer stringbuffer = new StringBuffer();
                String s3;
                while((s3 = bufferedreader.readLine()) != null) 
                {
                    stringbuffer.append(s3);
                    stringbuffer.append('\r');
                }
                bufferedreader.close();
                String s4 = stringbuffer.toString();
                String s5 = s4;
                return s5;
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
            String s2 = null;
            return s2;
        }
        finally
        {
            if(httpurlconnection != null)
            {
                httpurlconnection.disconnect();
            }
        }
    }

    public static void resetVersion()
    {
        DataOutputStream dataoutputstream = null;
        try
        {
            File file = new File((new StringBuilder()).append(getWorkingDirectory()).append(File.separator).append("bin").append(File.separator).toString());
            File file1 = new File(file, "version");
            dataoutputstream = new DataOutputStream(new FileOutputStream(file1));
            dataoutputstream.writeUTF("0");
            dataoutputstream.close();
        }
        catch(FileNotFoundException filenotfoundexception)
        {
            Logger.getLogger((net.minecraft.MinecraftUtil.class).getName()).log(Level.SEVERE, null, filenotfoundexception);
        }
        catch(IOException ioexception)
        {
            Logger.getLogger((net.minecraft.MinecraftUtil.class).getName()).log(Level.SEVERE, null, ioexception);
        }
        finally
        {
            try
            {
                dataoutputstream.close();
            }
            catch(IOException ioexception1)
            {
                Logger.getLogger((net.minecraft.MinecraftUtil.class).getName()).log(Level.SEVERE, null, ioexception1);
            }
        }
    }

    public static String getFakeLatestVersion()
    {
        try
        {
            File file = new File((new StringBuilder()).append(getWorkingDirectory()).append(File.separator).append("bin").append(File.separator).toString());
            File file1 = new File(file, "version");
            DataInputStream datainputstream = new DataInputStream(new FileInputStream(file1));
            String s = datainputstream.readUTF();
            datainputstream.close();
            if(s.equals("0"))
            {
                return "1285241960000";
            } else
            {
                return s;
            }
        }
        catch(IOException ioexception)
        {
            return "1285241960000";
        }
    }
    public static void readSettings()
    {
        try
        {
        	settings.clear();
            File file = new File(MinecraftUtil.getWorkingDirectory(), "lsettings");
            DataInputStream datainputstream;
            datainputstream = new DataInputStream(new FileInputStream(file));
            int flag = 0;
            while (datainputstream.available() >= 1)
            {
            	
            		if (datainputstream.readChar() == '1')
            		{
            			flag = 1;
            		} else {
            			flag = 0;
            		}
            		settings.add(flag);
            }
            datainputstream.close();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
       
    }

    public static void writeSettings()
    {
        try
        {
            File file = new File(MinecraftUtil.getWorkingDirectory(), "lsettings");
            DataOutputStream dataoutputstream;
            dataoutputstream = new DataOutputStream(new FileOutputStream(file));
            for (int s : settings)
    		{
            	if (s == 1)
            	{
            		dataoutputstream.writeChar('1');
            	} else {
            		dataoutputstream.writeChar('0');
            		
            	}
    		}
            dataoutputstream.close();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
    }

}
